package com.chengtong.shop.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.chengtong.shop.common.hibernate.BaseDao;
import com.chengtong.shop.common.util.StringUtil;
import com.chengtong.shop.entity.AdminRolefunction;

@Repository(value="roleFunctionDao")
public class RoleFunctionDao extends BaseDao<AdminRolefunction> {
	
	
	public List<Map<String, Object>> findFunctionByRoleid(String roleid,String isDisabled){
		String sql = "select func.id,rf.roleid,rf.functionid,func.functionname,func.url,func.icon,func.fatherid," +
				"func.isbottom,func.isdisabled " +
				" from admin_rolefunction rf left join sys_function func on rf.functionid = func.id where 1=1 ";
		String conditions = "";
		List<String> conditionList = new ArrayList<String>();
		
		if(!StringUtil.isBlank(roleid)){
			conditions += " and rf.roleid = ? ";
			conditionList.add(roleid);
		}
		if(!StringUtil.isBlank(isDisabled)){
			conditions += " and func.isdisabled = ? ";
			conditionList.add(isDisabled);
		}
		sql += conditions;
		sql += " order by func.sortid desc ";
		return super.findBySQLListMap(sql, conditionList.toArray(new String [0]));
	}
	
	public void deleteByRoleid(String roleid){
		String sql = " delete from admin_rolefunction where roleid=?";
		super.delete(sql,roleid);
	}
	
}
